;
(function (call) {
    var main = {
        userInfo: null,
        init: function () {
            this.initView();
            this.bindEvt();
        },
        initView: function () {
            var userInfo = $("#userInfo").data('info');
            $("#makeUser").val(userInfo.smuser.name);
            this.userInfo = userInfo;
            $("#publishTime").val(new Date().format('yyyy年MM月dd日hh时'));
            $("input").attr('autocomplete', 'off');
            this.getWxtsData();
        },
        getWxtsData: function () {
            var that = this;
            var params = {
                "product_id": 'TJ_WXTS',
                "fortime": "21:30",
                "queryTime": new Date().format('yyyy-MM-dd 20:00:00')
            }
            $.getJSON(api.internal.common.getProductDetail, params, function (res) {
                if (!res.isSuccess || JSON.stringify(res.data) == "{}") return;
                var fileName = res.data.data.fileName;
                var content = JSON.parse(res.data.data.content)
                content = content.tempData.curTagData
                $("#makeUser").val(content.i_wx01_mk01.val);
                $("#issuerName").val(content.i_wx01_ch02.val);
                $(".textarea textarea").val(content.i_wx01_msg04.val);
                $("#publishTime").val(content.i_wx01_dt03.val);
                $("#contentFrame").attr("src", "http://10.226.120.202:8088//ioffice/officeView.do?path=" + encodeURI(encodeURI(fileName)));
            })
        },
        publishWxts: function () {
            var that = this;
            var publishTime = $("#publishTime").val();
			var productInfo = $(".task-menu-list li.active").last().data('product');
            publishTime = publishTime.replace('年', '-').replace('月', '-').replace('日', ' ').replace('时', ':00:00')
            var tempData = {
                "tempData": {
                    "curTagData": {
                        "i_wx01_msg04": {
                            "val": $(".textarea textarea").val()
                        },
                        "i_wx01_ch02": {
                            "val": $("#issuerName").val()
                        },
                        "i_wx01_dt03": {
                            "val": $("#publishTime").val()
                        },
                        "i_wx01_mk01": {
                            "val": $("#makeUser").val()
                        }
                    }
                }
            }
            tempData = JSON.stringify(tempData)
            var params = 'product_id=TJ_WXTS&fortime=21:30&forecasterId=' + that.userInfo.smuser.iid + '&jsonStr=' + tempData + '&taskId=' + productInfo.taskId +''
            $.ajax({
                url: api.internal.wxts.pushlishWXTS,
                type: "POST",
                data: params,
                dataType: "json",
                success: function (res) {
                    if (res.isSuccess) {
                        alert("发布成功");
                        that.getWxtsData();
                    } else {
                        alert("发布失败");
                    }
                },
            })
        },
        bindEvt: function () {
            var that = this;
            $("#publishBtn").click(function () {
                that.publishWxts();
            })
        },
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    main.init();
})